package com.alibaba.servlet;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class MethodHandler {
    /**
     *  method.invoke(obj,)需要
     */
    private Object controller;
    private Method method;

    /**
     * spring中url支持正则
     */
//    private Pattern pattern;
    private String url;

    /**
     * 参数的顺序，为了进行参数绑定，Key 参数名， Value 代表第几个参数
     */
    private Map<String, Integer> paramIndexMapping;

    public MethodHandler(Object controller, Method method,String url) {
        this.controller = controller;
        this.method = method;
        this.url = url;
//        this.pattern = pattern;
        this.paramIndexMapping = new HashMap<>();
    }


    public Object getController() {
        return controller;
    }

    public void setController(Object controller) {
        this.controller = controller;
    }

    public Method getMethod() {
        return method;
    }

    public void setMethod(Method method) {
        this.method = method;
    }



    public Map<String, Integer> getParamIndexMapping() {
        return paramIndexMapping;
    }

    public void setParamIndexMapping(Map<String, Integer> paramIndexMapping) {
        this.paramIndexMapping = paramIndexMapping;
    }

    @Override
    public String toString() {
        return "MethodHandler{" +
                "controller=" + controller +
                ", method=" + method +
                ", url='" + url + '\'' +
                ", paramIndexMapping=" + paramIndexMapping +
                '}';
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }
}